<?php
 
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Hash;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class RecruitController extends Controller
{

    //===================添加=================
    public function getAdd(){
        //所有部门
         $res = DB::table('post')
         ->select('PostID','PostName') 
        ->get();
        //个人信息
        /*$info =  DB::table('recruit')
        ->join('post','post.PostId','=','recruit.RecruitID')
        ->select('PostID','PostName') 
         ->get();*/


    	//解析添加模板页面
    	return view('Personnel/Recruit/add',['res'=>$res]);
    }
    //执行添加操作
    public function postInsert(Request $request)
    {
          //所有部门
        /* $res = DB::table('post')
            ->get();
        dd($res);*/
        //个人信息
        
        
    	 $data =$request ->all();
         //$data['']
         //dd($data);  
         $info =  DB::table('post')
        ->where('post.PostId',$data['RecruitmentPost'])
        ->select('post.PostName') 
         ->first();
         //dd($info);

        // $date['PostID']=$info['PostId'];
         $data['RecruitmentPost'] =$info['PostName'];

    	 //执行数据添加
    	 $res =DB::table('Recruit') ->insert($data);
    	 if($res){
    	 	//成功跳转列表页
    	 	return redirect('Personnel/Recruit/index')->with('success','添加成功');
    	 }else{
    	 	return back() ->with('error','添加失败');
    	 }

    }
	//=========================显示=====================
    public function getIndex(Request $request){
    	//查询分页
	    	if($request ->input('post')){
	    		//搜索分页
	    		$res = DB::table('Recruit') ->where('RecruitmentPost','like','%'.$request->input['post'].'%')->paginate(1);
	    	}else{
	    		//查询所有分页
	    		$res = DB::table('Recruit')->paginate(1);
	    	}
            //dd($res);
	    $info = $request -> all();
    	//dd($Recruit);
    	//解析列表模板页面
	    return view('Personnel/Recruit/index',['res'=>$res,'info'=>$info]);
    }
    //=================================编辑=====================
    public function getEdit($id){
       //dd($id);
        //根据id查询员工数据信息
        $info= DB::table('Recruit')

        ->where('RecruitID',$id)->get();
        // dd($info);
    	//解析模板显示编辑的页面
        	return view('Personnel/Recruit.edit',['info'=>$info,'RecruitID'=>$id]);
    }
    //================执行编辑
    public function postUpdate(Request $request){
        $info = $request ->all();
        $id = $info['RecruitID'];
        DB::table('Recruit')->where('RecruitID',$id)->update($info);
        return redirect('Personnel/Recruit/index')->with('修改成功');
    }   
   







}
?>